package org.ala.tiktools.pacemaker.wakeups;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 唤醒类执行结果
 *
 * @author ala
 * @date 2024-12-18 15:17
 */
public enum WakeupResult {
    GO_ON(1, "go_on", "继续干活"),
    STOP(2, "stop", "到此为止")
    ;

    private int val;
    private String code;
    private String desc;

    WakeupResult(int val, String code, String desc) {
        this.val = val;
        this.code = code;
        this.desc = desc;
    }

    static Map<Integer, WakeupResult> valueOfVal;
    public static WakeupResult valueOfVal(int val) {
        if (valueOfVal == null) {
            synchronized (WakeupResult.class) {
                if (valueOfVal == null) {
                    valueOfVal = Arrays.stream(values()).collect(Collectors.toMap(e -> e.val, e -> e, (o,n)->n));
                }
            }
        }
        return valueOfVal.get(val);
    }

    static Map<String, WakeupResult> valueOfCode;
    public static WakeupResult valueOfCode(String code) {
        if (valueOfCode == null) {
            synchronized (WakeupResult.class) {
                if (valueOfCode == null) {
                    valueOfCode = Arrays.stream(values()).collect(Collectors.toMap(e -> e.code, e -> e, (o,n)->n));
                }
            }
        }
        return valueOfCode.get(code);
    }

    public int getVal() {
        return val;
    }

    public void setVal(int val) {
        this.val = val;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }
}
